home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / WRWIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-09  |  1.3 KB  |  59 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. #include <assert.h>
  5. #include <mem.h>
  6. #include "window.h"
  7. #include "_window.h"
  8.  
  9. int winwrite(windowtype *window, char *string)
  10. {
  11.     int linelen,pos,strln,rtn,i,size;
  12.  
  13.     /* Only background write to a window in the background */
  14.     if ( window->previous == NULL )
  15.     {
  16.         cputs(string);
  17.         return 0;
  18.     }
  19.  
  20.     if ( !backimage || imagefor != window )
  21.     {
  22.         invalidate_backimage();
  23.         if ( (backimage = getwinimage(window,1)) == NULL )
  24.             return -1;
  25.         imagefor = window;
  26.     }
  27.  
  28.     linelen = (window->right-window->left)-1;
  29.     pos = (window->ypos-1) * linelen + (window->xpos-1);
  30.     strln = strlen(string);
  31.     i = 0;
  32.     size = linelen * (window->bottom-window->top-1);
  33.     while ( pos + strln > size )
  34.     {
  35.         int t;
  36.         strtoscrn(&backimage[pos << 1],&string[i], window->attr,
  37.             t = size - pos);
  38.         i       += t;
  39.         strln   -= t;
  40.         pos     += t - linelen;
  41.  
  42.         /* Scroll window */
  43.         memmove(backimage, &backimage[linelen << 1], (size - linelen) << 1);
  44.         chartoscrn(&backimage[(size - linelen) << 1], ' ', window->attr,
  45.             linelen);
  46.     }
  47.     strtoscrn(&backimage[pos << 1], &string[i], window->attr, strln);
  48.     pos += strln;
  49.  
  50.     if ( (rtn = putwinimage(window, backimage, 1, 1)) != 0 )
  51.         return rtn;
  52.  
  53.     /* update cursor position */
  54.     window->xpos = (pos % linelen) + 1;
  55.     window->ypos = (pos / linelen) + 1;
  56.  
  57.     return 0;
  58. }
  59.